import { getProfileDetail, getProfileInfo } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'

export default {
  namespaced: true,
  state: {
    token: getToken(),
    userInfo: {}
  },
  mutations: {
    updateToken(state, token) {
      state.token = token
      setToken(token)
    },
    updateUserInfo(state, info) {
      state.userInfo = info
    }

  },
  actions: {
    async  getuserInfo(context) {
      const res = await getProfileInfo()
      const info = await getProfileDetail(res.data.userId)
      context.commit('updateUserInfo', { ...res.data, ...info.data })
      // console.log(res.data, 'res.data')
      return res.data.roles.menus
    }
  }
}

